﻿Imports System.IO
Imports System.Data.OleDb
Public Class Frm_Login
    Structure Account
        Dim username As String
        Dim password As String
        Dim acctype As String
    End Structure

    Public lsAcc As List(Of Account)

    Public banve As VeDTO

    Structure SLOT
        Dim sl As Button
        Dim st As Integer
    End Structure

    Public arr(100, 100) As SLOT

    Public username As String
    Public acctype As String

    Private Sub btnDangKy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDangKy.Click
        Frm_DangKy.ShowDialog()
    End Sub



    Private Sub Frm_Login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        RadioButton1.Checked = True
    End Sub

    Private Sub btnDangNhap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDangNhap.Click
        lsAcc = New List(Of Account)
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = ""
        If RadioButton1.Checked = True Then
            str = "select MaNV, MatKhau, TenChucVu from NHANVIEN, CHUCVU where NHANVIEN.MaChucVu = CHUCVU.MaChucVu"
        Else
            str = "select IDThanhVien, MatKhau from THANHVIEN"
        End If

        Dim cmd As New OleDbCommand(str, cn)
        Dim rd As OleDbDataReader = cmd.ExecuteReader()
        Dim acc As Account
        While (rd.Read())
            If RadioButton1.Checked = True Then
                acc = New Account()
                acc.username = rd("MaNV").ToString()
                acc.password = rd("MatKhau").ToString()
                acc.acctype = rd("TenChucVu").ToString()
            Else
                acc = New Account()
                acc.username = rd("IDThanhVien").ToString()
                acc.password = rd("MatKhau").ToString()
                acc.acctype = "Khách hàng"
            End If

            lsAcc.Add(acc)
        End While
        cn.Close()


        Dim flag As Integer = 0
        For i = 0 To lsAcc.Count() - 1 Step 1
            If (txtTenDN.Text = lsAcc(i).username And txtMatKhau.Text = lsAcc(i).password) Then
                flag = 1
                username = lsAcc(i).username
                acctype = lsAcc(i).acctype
                If (lsAcc(i).acctype = "Admin") Then
                    Dim frm As New Frm_Admin()
                    frm.ShowDialog()
                ElseIf (lsAcc(i).acctype = "Quản lý") Then
                    Dim frm As New Frm_NhanVienQuanLy()
                    frm.ShowDialog()
                ElseIf (lsAcc(i).acctype = "Bán vé") Then
                    Dim frm As New Frm_NhanVienBanVe()
                    frm.ShowDialog()
                ElseIf (lsAcc(i).acctype = "Trưởng bộ phận") Then
                    Dim frm As New Frm_TruongBoPhan()
                    frm.ShowDialog()
                ElseIf (lsAcc(i).acctype = "Khách hàng") Then
                    Dim frm As New Frm_KhachHang()
                    frm.IDKhachHang = txtTenDN.Text
                    frm.ShowDialog()
                End If
                txtTenDN.Text = ""
                txtMatKhau.Text = ""
            End If
        Next
        If flag = 0 Then MessageBox.Show("Vui lòng kiểm tra lại tên đăng nhập và mật khẩu!!!")
    End Sub

    Private Sub btnNhapLai_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNhapLai.Click
        txtTenDN.Text = ""
        txtMatKhau.Text = ""
        txtTenDN.Select()
    End Sub

    
End Class